/*
 * User: rant
 * Date: 12/12/2006
 *
 *
 */
package laMalinche.testingPlayGround.flow;

import laMalinche.propertyChangeAdapters.model.OgnlHolder;

import java.util.*;

/**
 *
 */
public class Collector<T extends OgnlHolder> implements CollectorIfc {
	//    List<FieldElementIfc> fields;
	Set<String> fields = new HashSet<String>();

	public T getModel() {
		return model;
	}

	public void setModel(final T model) {
		this.model = model;
	}

	T model;

	public void setName(String name) {
		this.name = name;
	}

	private String name;

	public Collector() {
		fields = new HashSet<String>();
	}

	public Collector(T holder, String... args) {
		fields = new HashSet<String>();
		model = holder;
        fields.addAll(Arrays.asList(args));
	}

	public Set<String> getFields() {
		return fields;
	}

	public void setFields(Set<String> fields) {
		this.fields = fields;
	}

	public void addField(String field) {
		fields.add(field);
	}

	public String getName() {
		return name;
	}

    @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || getClass() != object.getClass()) {
            return false;
        }

        Collector collector = (Collector) object;

        if (fields != null ? !fields.equals(collector.fields) : collector.fields != null) {
            return false;
        }
        if (model != null ? !model.equals(collector.model) : collector.model != null) {
            return false;
        }
        return !(name != null ? !name.equals(collector.name) : collector.name != null);

    }

    //    @Override
//    public boolean equals(Object object) {
//		final Collector collector = ((Collector) object);
//		return getModel().equals(collector.getModel()) && getFields().equals(collector.getFields());
//	}

	@Override
    public int hashCode() {
		return getModel().hashCode() + getFields().hashCode();
	}
}